/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-08-01 16:54:44
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-08-01 22:40:44
 */

import React from "react";
import { RouterContext } from "./Context";

export default class Link extends React.Component {
  static contextType = RouterContext;
  constructor(props) {
    super(props);
    this.state = {};
  }
  handleClick = (event) => {
    event.preventDefault();
    // 事件跳转
    this.context.history.push(this.props.to);
  };
  render() {
    const { to, children, ...restProps } = this.props;
    return (
      <a onClick={this.handleClick} href={to} {...restProps}>
        {children}
      </a>
    );
  }
}
